namespace CE.Parsers.VB
{
	using System;
    using System.Collections.Specialized;
	using System.IO;

    public class Util
	{
		#region Fields

		public TextWriter output;

		string identStr = "";
		StringCollection linePush = new StringCollection();

		#endregion Fields

		#region Methods

		public void CloseBlock()
		{
			Unident();
			Writeline("}" + Environment.NewLine);
		}

		public string ConvertByX(string byx)
		{
			if (byx == "ByVal")
				return "";
			else
				return " ";
		}

		public string ConvertModifier(string mod)
		{
			switch (mod) {
			    case "Overrides":
				    return "override ";
			    case "Shared":
				    return "static";
			    case "Friend":
				    return "internal";
			    default:
				    return mod.ToLower() + " ";
			}
		}

		public string ConverteLogicalOp(string str)
		{
			switch (str) {
			    case "=":
				    return " == ";
			    case "<>":
				    return " != ";
			    default:
				    return " " + str + " ";
			}
		}

		public string ConverteString(string str)
		{
			if (str.IndexOf('\\') >= 0)
				return "@" + str;
			else
				return str;
		}

		public string ConverteTipo(string tipo)
		{
			switch (tipo) {
			    case "Integer":
				    return "int";
			    case "String":
				    return "string";
			    case "Boolean":
				    return "bool";
			    case "Long":
				    return "long";
			    case "Single":
				    return "float";
			    case "Double":
				    return "double";
			    case "Short":
				    return "short";
			    case "Byte":
				    return "byte";
			    case "Char":
				    return "char";
			    default:
				    return tipo;
			}
		}

		public void Ident()
		{
			identStr += "    ";
		}

		public void OpenBlock()
		{
			Writeline("{");
			Ident();
		}

		public void PushLine(string line)
		{
			linePush.Add(line);
		}

		public void Unident()
		{
			identStr = identStr.Substring(0, identStr.Length - 4);
		}

		public void Writeline(string line)
		{
			output.Write(identStr);
			output.WriteLine(line);
			if (linePush.Count != 0) {
				foreach (string s in linePush) {
					output.Write(identStr);
					output.WriteLine(s);
				}
				linePush.Clear();
			}
		}

		#endregion Methods
	}
}